package com.core.app
import com.core.bean.{CategoryCountInfo, UserVisitAction}
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD
object PracticeApp {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setAppName("Practice").setMaster("local[2]")
    val sc = new SparkContext(conf)
    // 1. 读取文件中的数据
    val lineRDD: RDD[String] = sc.textFile("D:\\java\\tjetc\\scala_big\\src\\main\\scala\\com\\core\\input\\user_visit_action.txt")
    // 2. 类型调整
    val userVisitActionRDD: RDD[UserVisitAction] = lineRDD.map(line => {
      val splits: Array[String] = line.split("_")
      UserVisitAction(
        splits(0),
        splits(1).toLong,
        splits(2),
        splits(3).toLong,
        splits(4),
        splits(5),
        splits(6).toLong,
        splits(7).toLong,
        splits(8),
        splits(9),
        splits(10),
        splits(11),
        splits(12).toLong)
    })
    // 需求 1
    val categoryTop10: List[CategoryCountInfo] = CategoryTop10App.statCategoryTop10(sc, userVisitActionRDD)
    println(categoryTop10)

    sc.stop()
  }
}
